package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.dto.MemberLoginDto;
import com.itheima.common.entity.Result;
import com.itheima.service.MemberService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @className MemberController
 */
@RestController
@RequestMapping("/member")
@RequiredArgsConstructor
@Slf4j
public class MemberController {

    private final MemberService memberService;

    /**
     * 会员登录
     * @param memberLoginDto 登录条件：手机号、验证码
     * @return
     */
    @PostMapping("/login")
    public Result memberLogin(@RequestBody MemberLoginDto memberLoginDto){
        String msg = memberService.memberLogin(memberLoginDto);
        if (!msg.equals(MessageConstant.LOGIN_SUCCESS)) {
            return new Result(false, msg);
        }
        return new Result(true, msg);
    }
}
